<template>
	<view>
		<view class="user-info-container">
			<view class="user-info-item">
				账号：{{userInfo.username}}
			</view>
			<view class="user-info-item">
				昵称：{{userInfo.nickname}}
			</view>
			<view class="user-info-item">
				性别：{{userInfo.sex===0?'男':'女'}}
			</view>
			<view class="user-info-item">
				邮箱：{{userInfo.userEmail}}
			</view>
			<view class="user-info-item">
				真名：{{userInfo.name}}
			</view>
			<button type="primary" class="update-info" @click="toUpdateInfo">修改信息</button>
		</view>
		
	</view>
</template>

<script>
	import userApi from '@/api/myUser.js'
	export default {
		data() {
			return {
				user: uni.getStorageSync('user'),
				userInfo: {
					username: '',
					nickname: '',
					sex: '',
					userEmail: '',
					name: ''
				}
			}
		},
		onShow() {
			this.getLoginUser()
		},
		methods: {
			// 获取用户信息
			getLoginUser() {
				userApi.get(this.user.userId).then(res => {
					this.userInfo.username = res.data.username;
					this.userInfo.nickname = res.data.nickname;
					this.userInfo.sex = res.data.sex;
					this.userInfo.userEmail = res.data.userEmail;
					this.userInfo.name = res.data.name;
				})
			},
			// 跳转到修改用户信息页面
			toUpdateInfo() {
				uni.navigateTo({
					url: '/pages/update-info/update-info'
				})
			}
		}
	}
</script>

<style>
@import url('./index.css')
</style>
